home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / java_Win / demo / UnderConstruction / JackhammerDuke.class (.txt) < prev    next >
Encoding:
Java Class File  |  1995-10-12  |  2.6 KB  |  77 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6.  
  7. public class JackhammerDuke extends Applet implements Runnable {
  8.    int seqslot;
  9.    int nimgs = 4;
  10.    Image imgs;
  11.    String dir;
  12.    Thread kicker;
  13.    int pause;
  14.    // $FF: renamed from: x double
  15.    double field_0;
  16.    int imgsWidth = 328;
  17.    int imgsHeight = 90;
  18.    private int[] sequence = new int[]{2, 1, 0, 1, 0, 1, 0, 1, 2, 1, 0, 2, 0, 1, 0, 2, 3};
  19.    boolean erase;
  20.  
  21.    public void run() {
  22.       Thread.currentThread().setPriority(1);
  23.       this.imgs = ((Applet)this).getImage(((Applet)this).getCodeBase(), "images/jack.gif");
  24.       if (this.imgs != null) {
  25.          int var10002 = this.imgsWidth / this.nimgs;
  26.  
  27.          for(this.field_0 = (double)((((Component)this).size().width - var10002) / 2); ((Component)this).size().width > 0 && ((Component)this).size().height > 0 && this.kicker != null; this.seqslot = (this.seqslot + 1) % this.sequence.length) {
  28.             if (this.seqslot == 0) {
  29.                ((Applet)this).play(((Applet)this).getCodeBase(), "audio/jackhammer-short.au");
  30.             }
  31.  
  32.             ((Component)this).repaint();
  33.  
  34.             try {
  35.                Thread.sleep((long)(this.seqslot == this.sequence.length - 1 ? 500 : 100));
  36.             } catch (InterruptedException var1) {
  37.             }
  38.          }
  39.       }
  40.  
  41.    }
  42.  
  43.    public void update(Graphics g) {
  44.       if (this.erase || this.sequence[this.seqslot] == 3) {
  45.          g.setColor(Color.lightGray);
  46.          g.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  47.          this.erase = false;
  48.       }
  49.  
  50.       this.paint(g);
  51.    }
  52.  
  53.    public void paint(Graphics g) {
  54.       int loopslot = this.sequence[this.seqslot];
  55.       if (this.imgs != null && loopslot < this.nimgs) {
  56.          int w = this.imgsWidth / this.nimgs;
  57.          this.field_0 = Math.max((double)0.0F, Math.min((double)(((Component)this).size().width - w), this.field_0 + Math.random() * (double)4.0F - (double)2.0F));
  58.          g.clipRect((int)this.field_0, 0, w, this.imgsHeight);
  59.          g.drawImage(this.imgs, (int)this.field_0 - loopslot * w, 0, this);
  60.          this.erase = loopslot == 3;
  61.       }
  62.  
  63.    }
  64.  
  65.    public void start() {
  66.       if (this.kicker == null) {
  67.          this.kicker = new Thread(this);
  68.          this.kicker.start();
  69.       }
  70.  
  71.    }
  72.  
  73.    public void stop() {
  74.       this.kicker = null;
  75.    }
  76. }
  77.